# Pinecone 手写数字识别 - 运行脚本

Write-Host "=====================================================================" -ForegroundColor Cyan
Write-Host "          Pinecone 手写数字识别项目 - 自动运行脚本" -ForegroundColor Cyan
Write-Host "=====================================================================" -ForegroundColor Cyan
Write-Host ""

# 步骤 1: 同步依赖
Write-Host "[步骤 1/4] 正在同步安装依赖..." -ForegroundColor Yellow
uv sync
if ($LASTEXITCODE -ne 0) {
    Write-Host "依赖安装失败！" -ForegroundColor Red
    exit 1
}
Write-Host "✓ 依赖安装完成" -ForegroundColor Green
Write-Host ""

# 步骤 2: 运行示例（可选）
Write-Host "[步骤 2/4] 是否运行 Pinecone 示例？(Y/N)" -ForegroundColor Yellow
$runExample = Read-Host "选择"
if ($runExample -eq "Y" -or $runExample -eq "y") {
    Write-Host "正在运行 pinecone_example.py..." -ForegroundColor Cyan
    uv run python pinecone_example.py
    Write-Host ""
    Write-Host "按任意键继续..." -ForegroundColor Yellow
    $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
Write-Host ""

# 步骤 3: 训练模型
Write-Host "[步骤 3/4] 正在训练模型并创建 Pinecone 索引..." -ForegroundColor Yellow
Write-Host "这将需要 2-5 分钟，请耐心等待..." -ForegroundColor Cyan
uv run python pinecone_train.py
if ($LASTEXITCODE -ne 0) {
    Write-Host "训练失败！" -ForegroundColor Red
    exit 1
}
Write-Host "✓ 训练完成" -ForegroundColor Green
Write-Host ""

# 步骤 4: 启动 Web 应用
Write-Host "[步骤 4/4] 正在启动 Web 应用..." -ForegroundColor Yellow
Write-Host "Web 应用即将启动，请在浏览器中打开显示的 URL" -ForegroundColor Cyan
Write-Host "提示：第一次识别会较慢（需要初始化连接），后续会很快" -ForegroundColor Magenta
Write-Host ""
uv run python optimal_knn_webapp_pinecone.py
